#include<stdio.h>
#include<conio.h>
typedef struct list{
    long data;
    list *next,*previous;
};
typedef struct neo{
    long max;
    list *index;
};
neo ngan[10001],tram[10001],chuc[100000];
long n,m,luong[1000001];
void freeList(list *a){
    if(a!=NULL){
        while((*a).next!=NULL){
            a=(*a).next;
            delete (*a).previous;
        }
        delete a;
    }
}
void insertList(list *a,long index){
    list *b=a;
    while(a!=NULL){
        if((*a).data==index)return;
        a=(*a).next;
    }
    list *c=new list;
    (*c).data=index;
    (*c).next=b;
    (*c).previous=NULL;
    b=c;
}
void removeList(list *a,long index){
    list *b;
    while(a!=NULL && (*a).data!=index)
        a=(*a).next;
    if((*a).data==index){
        (*(*a).previous).next=(*a).next;
        (*(*a).next).previous=(*a).previous;
        delete a;
    }
}
void set(long index,long value){
    if(ngan[index/1000].max<value){
        freeList(ngan[index/1000].index);
        ngan[index/1000].max=value;
        ngan[index/1000].index=new list;
        (*ngan[index/1000].index).data=index;
        (*ngan[index/1000].index).next=(*ngan[index/1000].index).previous=NULL;
    }else if(ngan[index/1000].max==value)insertList(ngan[index/1000].index,index);
        else if(luong[index]==ngan[index/1000].max)
            removeList(ngan[index/1000].index,index);
    
    if(tram[index/100].max<value){
        freeList(tram[index/100].index);
        tram[index/100].max=value;
        tram[index/100].index=new list;
        (*tram[index/100].index).data=index;
        (*tram[index/100].index).next=(*tram[index/100].index).previous=NULL;
    }else if(tram[index/100].max==value)insertList(tram[index/100].index,index);
        else if(luong[index]==tram[index/100].max)
            removeList(tram[index/100].index,index);
    luong[index]=value;

}
long getMaxLuong(long start,long end){
    long i,max=0;
    for(i=start;i<=end;i++)
        if(max<luong[i])max=luong[i];
    return max;
}
long getMaxArray(neo *list,long start,long end){
    long i,max=0;
    for(i=start;i<=end;i++)
        if(max<list[i].max)max=list[i].max;
    return max;
}
long get(long start,long stop){
    long i,max=getMaxArray(ngan,start/1000+1,stop/1000-1),maxTemp=0,begin,end;

    if(start/1000!=stop/1000){
        if(max<ngan[start/1000].max){
            for(i=start/100+1;i%10!=0 && i>start/100+1;i++)
                if(tram[i].max>max)max=tram[i].max;
        }
        if(max<ngan[stop/1000].max){
            begin=(stop/1000)*10;
            end=stop/100-1;
            maxTemp=getMaxArray(tram,begin,end);
            if(maxTemp>max)max=maxTemp;
        }
        maxTemp=getMaxLuong(start,((start/100+1)*100-1));
        if(maxTemp>max)max=maxTemp;
        
        maxTemp=getMaxLuong(stop/100*100,stop);
        if(maxTemp>max)max=maxTemp;
    }else{
        maxTemp=getMaxArray(tram,start/100+1,stop/100-1);
        if(maxTemp>max)max=maxTemp;
        if(start/100!=stop/100){
            
            begin=start;
            end=(start/100+1)*100;
            maxTemp=getMaxLuong(stop/100*100,stop);
            if(maxTemp>max)max=maxTemp;
            
            begin=stop - stop%100;
            end=stop;
            maxTemp=getMaxLuong(begin,end);
            if(maxTemp>max)max=maxTemp;
        }else{
            maxTemp=getMaxLuong(start,stop);
            if(maxTemp>max)max=maxTemp;
        }
    }    
    return max;
}
void process(){
    long i,m,n,u,v;
    char c,k,enter=0;
    FILE *fpinp=fopen("QUERY.INP","r");
    FILE *fpout=fopen("QUERY.OUT","w");
    fscanf(fpinp,"%ld%ld",&n,&m);
    for(i=1;i<=m;i++){
        fscanf(fpinp,"%c%c%ld%ld",&k,&c,&u,&v);
        if(c=='S')set(u,v);
        else {
            if(enter)fprintf(fpout,"\n");
            if(u<v)fprintf(fpout,"%ld",get(u,v));
                else fprintf(fpout,"%ld",get(v,u));
            enter=1;
        }
    }
    fclose(fpinp);
}
int main(){
    process();
    return 0;
}

